package com.hailiang.study.javase.java.util.function;

import org.junit.Test;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author hailiang.jiang
 * @date 2022年07月12 14:58
 */
public class Function_identity {

    @Test
    public void test_identity01() {
        List<String> demoList = Arrays.asList("my", "name", "is", "jiang", "hailiang");

        List<String> result01 = demoList.stream().map(Function.identity()).map(item -> item).collect(Collectors.toList());
        System.out.println(result01);

        Map<String, Integer> lengthMap = demoList.stream().collect(Collectors.toMap(Function.identity(), item -> item.length(), (o, n) -> o, LinkedHashMap::new));
        System.out.println(lengthMap);

        Map<String, String> stringToMap = demoList.stream().collect(Collectors.toMap(Function.identity(), Function.identity(), (o, n) -> o, LinkedHashMap::new));
        System.out.println(stringToMap);

        // 下面的语句会报错
        //demoList.stream().mapToInt(Function.identity());
    }

}
